/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package battle.ship.model;

import java.util.Random;

/**
 *
 * @author Carlos
 */
public class Point {
    private int x;
    private int y;
    
    public Point(int x, int y){
        this.x = x;
        this.y = y;
    }
    
    public int getX(){
        return x;
    }
    
    public int getY(){
        return y;
    }
    
    public void setX(int x){
        this.x=x;
    }
    
    public void setY(int y){
        this.y=y;
    }
    
    public Point subtract(Point point){
        return new Point( this.x - point.x, this.y - point.y);
    }
    
    @Override
    public String toString(){
        return String.format("Posição X: %d Y: %d", this.x, this.y);
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 53 * hash + this.x;
        hash = 53 * hash + this.y;
        return hash;
    }
    
    @Override
    public boolean equals(Object obj){
        if (obj == this)
        {
            return true;
        }
        if (obj == null)
        {
            return false;
        }
        if (obj instanceof Point)
        {
            Point other = (Point)obj;
            return (this.x == other.x && this.y == other.y);
        }
        return false;
    }
    
    public static Point Random(int size){
        Random rnd = new Random();
        int x = rnd.nextInt(size);
        int y = rnd.nextInt(size);
        return new Point(x,y);
    }
}
